﻿using System.Linq;

namespace xWF.Examples.Tkmv
{
    public sealed class TkmvWorkItem
    {
        public int TkmvId { get; private set; }

        public TkmvWorkItem(int tkmvId)
        {
            TkmvId = tkmvId;
        }

        public TkmvStatus CardStatus()
        {
            //var tkmv = Service<TkmvSvc>().GetById(TkmvId);
            //return tkmv == null ? TkmvStatus.None : tkmv.Status;

            return TkmvStatus.New;
        }

        public void UpdateCardStatus(TkmvStatus status)
        {
            //var tkmv = GetCard();
            //if (tkmv.Status != status)
            //{
            //    tkmv.Status = status;
            //    UpdateCard(tkmv);
            //}
        }

        public bool CheckRole(params UserRoleTkmv[] expectedRoles)
        {
            var role = UserRoleTkmv.Consumer; //ServiceManager.Current.Service<TkmvSvc>().GetCurrentUserRole(TkmvId);
            return expectedRoles.Any(expectedRole => (role & expectedRole) == expectedRole);
        }

        //public Tkmv GetCard()
        //{
        //    var tkmv = Service<TkmvSvc>().GetById(TkmvId);

        //    if (tkmv == null)
        //    {
        //        throw new InvalidOperationException(string.Format("Карта с ID {0} не найдена", TkmvId));
        //    }

        //    return tkmv;
        //}

        //public void UpdateCard(Tkmv tkmv)
        //{
        //    Service<TkmvSvc>().Update(tkmv);
        //}

        //public T Service<T>()
        //{
        //    return ServiceManager.Current.Service<T>();
        //}
    }
}
